home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 012a / uarttype.zip / UARTTYPE.MSG < prev   
Text File  |  1991-03-21  |  4KB  |  161 lines

  1. FROM:    Yousuf Khan            Area # 17 (Assembly Language )
  2. TO:    Y'ALL                21 Mar 91
  3. SUBJECT: *.pas to *.asm
  4.  
  5. Well it seems the impossible has happened to me: I now understand
  6. Assembler more than I understand Pascal. So I found this routine,
  7. written in TurboPascal, that detects what type of UART you have running.
  8. I haven't used TP in 3 years+, so I need a translation of this pascal
  9. code to assembler, if you will:
  10.  
  11.       xword:=MemW[BIOSdseg : 2 * i - 2];
  12.     Writeln('$', hex(xword, 4));
  13.     xbyte2:=Port[xword + 2];
  14.     Port[xword + 2]:=$C1;
  15.     for temp:=1 to 2 do;
  16.     xbyte3:=Port[xword + 2];
  17.     Port[xword + 2]:=xbyte2;
  18.     case ((xbyte3 and $C0) shr 6) of
  19.       0: begin
  20.          xbyte2:=Port[xword + 7];
  21.          Port[xword + 7]:=$FA;
  22.          for temp:=1 to 2 do;
  23.          if Port[xword + 7] = $FA then begin
  24.            Port[xword + 7]:=$AF;
  25.            for temp:=1 to 2 do;
  26.            if Port[xword + 7] = $AF then begin
  27.          Port[xword + 7]:=xbyte2;
  28.          Write('16450')
  29.            end
  30.            else
  31.          Write('8250')
  32.          end
  33.          else
  34.            Write('8250')
  35.          end;
  36.       1: Write('???');
  37.       2: Write('16550');
  38.       3: Write('16550A')
  39.  
  40. This is of course a routine to detect the type of UART. There are
  41. certain things I'm having trouble understanding. BIOSdseg, is this a
  42. variable or a built-in TPascal function? $C0 & $C1, what are these?
  43.  
  44. Yousuf Khan
  45.  
  46.  * Origin: To never lose characters again (1:163/215.6)
  47.  
  48. FROM:    Scott Canion            Area # 17 (Assembly Language )
  49. TO:    Yousuf Khan            21 Mar 91
  50. SUBJECT: Re: *.pas to *.asm
  51.  
  52. On 19-Mar-91, sources inform us that Yousuf Khan @ 1:163/215.6 said:
  53.  
  54.  YK> Well it seems the impossible has happened to me: I now understand
  55.  YK> Assembler more than I understand Pascal.
  56.  
  57. Thanks for the pascal code, Yousuf, it is very helpful.  Here is the assembly
  58. version.  I tried to keep the variables close to the pascal source.  Are you
  59. sure you have programmed in Pascal before? :-)
  60.  
  61. ========================== beginning of program =============================
  62.  
  63. title "UART Detector"
  64. page 60, 132
  65.  
  66. ; comments -- the WRITE function is left up to your own implementation
  67.  
  68. ; constants
  69.  
  70. BIOSdseg    equ    40h        ; data segment for BIOS
  71. i        equ    1        ; COM PORT (1-4)
  72.  
  73.     .model    tiny            ; tiny model (.COM)
  74.     .code
  75.     org    100h            ; .COM files start at 100h
  76.  
  77. entry:
  78.     jmp    start            ; jump to start of progarm
  79.  
  80. ; variables
  81.  
  82. xword        dw    ?
  83. xbyte2        db    ?
  84. xbyte3        db    ?
  85.  
  86. jmp_table   dw      uart_8250_or_16450, uart_unknown, uart_16550, uart_16550a
  87.  
  88. ; ------------------------ MAIN ------------------------------
  89.  
  90. start    proc
  91.     mov    ax, BIOSdseg
  92.     mov    es, ax            ; move bios data segment into ES
  93.     mov    dx, es:[2*i-2]        ; get offset for serial port
  94.     mov    xword, dx        ; xword := serial port base address
  95.     add    dx, 2            ; dx := dx + 2
  96.     in    al, dx            ; al := port [dx]
  97.     mov    xbyte2, al        ; xbyte2 := al
  98.     mov    al, 0c1h        ; al := $C1
  99.     out    dx, al            ; port [dx] := al
  100.     in    al, dx            ; al := port [dx]
  101.     and    al, 0c0h        ; al := (al AND $C0)
  102.     mov    cl, 5            ; cl := 5
  103.     shr    al, cl            ; al := (al shr 5) (5 for word jmp)
  104.     mov    ah, 0            ; ah := 0
  105.     mov    bp, ax            ; bp := ax (al)
  106.     mov    al, xbyte2        ; al := xbyte2
  107.     out    dx, al            ; port [dx] := al
  108.     jmp    cs:[jmp_table+bp]    ;
  109.  
  110. uart_8250_or_16450:
  111.     mov    dx, xword        ; dx := xword
  112.     add    dx, 7            ; dx := dx + 7
  113.     in    al, dx            ; al := port [dx]
  114.     mov    xbyte2, al        ; xbyte2 := al
  115.     mov    al, 0fah        ; al := $FA
  116.     out    dx, al            ; port [dx] := al
  117.     in    al, dx            ; al := port [dx]
  118.     cmp    al, 0fah        ; if (al <> $FA)
  119.     jne    uart_16450        ; then uart is 16450
  120.     mov    al, 0afh        ; al := $AF
  121.     out    dx, al            ; port [dx] := al
  122.     in    al, dx            ; al := port [dx]
  123.     cmp    al, 0afh        ; if (al <> $AF)
  124.     jne    uart_8250        ; then uart is 8250
  125.     mov    al, xbyte2        ; else al := xbyte2
  126.     out    dx, al            ; port [dx] := al
  127.     jmp    uart_16450        ; uart is 16450
  128.  
  129. uart_8250:
  130.     write    "8250"            ; display "8250"
  131.     jmp    exit
  132.  
  133. uart_16450:
  134.     write    "16450"            ; display "16450"
  135.     jmp    exit
  136.  
  137. uart_unknown:
  138.     write    "???"            ; display "unknown"
  139.     jmp    exit
  140.  
  141. uart_16550:
  142.     write    "16550"            ; display "16550"
  143.     jmp    exit
  144.  
  145. uart_16550a:
  146.     write    "16550A"        ; display "16550A"
  147.     jmp    exit
  148.  
  149. exit:
  150.     mov    ax, 4c00h
  151.     int    21h            ; exit to DOS
  152. start    endp                ; end of proc
  153.  
  154. END    entry                ; end of program
  155.  
  156. ============================== end of program ===============================
  157.  
  158. --- QM v1.00
  159.  * Origin: Scott's Excellent BBS HST/V.32bis (1:382/17.0)
  160.  
  161.